import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  //变量
  state: {
    //是否登录
    isLogin : true?true:false,//从window.localStorage中判断是否有token(window.localStorage.getItem("token"))
    token : '',//加密
    loginUser : {

    },
    samllType:[]
  },
  //方法
  //store.commit（"",loginUser）
  mutations: {
    SET_LOGIN(state,loginUser){
      state.loginUser = loginUser;
      state.isLogin = true;
      state.token = loginUser.token;//跟登录一致
      //本地内存
      window.localStorage.setItem("token",loginUser)
    },
    SET_LOGOUT(state){
      state.loginUser = "";
      state.isLogin = false;
      state.token = "";//跟登录一致
    }
  },
  //异步
  //store.dispatch('increment')
  actions: {
    login(context,loginUser){
      context.commit('SET_LOGIN',loginUser);
    },
    logout(){
      context.commit('SET_LOGOUT');
    }
  },
  //模块
  modules: {
  }
})
